/**
 * 模态框
 */
module.exports = function($scope, $modalInstance, $resource, item, flag){

    //页面控制对象
	$scope.item_set = {
		//接口类型下拉菜单
		'logintype': [
			{ 'label': '需要登录', 'value': '1' },
			{ 'label': '无需登录', 'value': '0' }
		]
	};
    
    init();
    function init(){
        $scope.obj = item;
        $scope.obj.logintype = $scope.item_set.logintype[0];
        if(flag){
            $scope.obj.state_c = !item.state;
        } else {
            $scope.obj.state_c = item.state;
            if(!item.type){
                $scope.obj.logintype = $scope.item_set.logintype[1];
            }
        }
    }

    $scope.save = function () {
        $scope.obj.type = $scope.obj.logintype.value;
        $scope.obj.state = $scope.obj.state_c?'1':'0';
        $resource('/api/as/sc/uservisit/save', {}, {}).save($scope.obj, function(res){
			if(res.errcode === 0){
                $modalInstance.close($scope.obj);
			}else{
				alert(res.errmsg);
			}
		});
    };

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
};